from flask import request, jsonify,session,g

import time,os
from ..func.token_auth import auth as http_auth
from . import main
from .. import db



@main.route("/")
def index():
    return "index"


# 获取表单提交的图片
@main.route('/get_img',methods=['POST'])
def get_img():
	# 通过表单中name值获取图片
    imgData = request.files["image"]
    # 设置图片要保存到的路径
     #获取项目当前绝对路径
    # 比如我的项目在桌面上存放则得到——"C:\Users\asus\Desktop\shou"
    basedir = os.path.abspath(os.path.dirname(__file__))
    path = basedir + "/static/upload/"
    print(path)
    # 获取图片名称及后缀名
    imgName = imgData.filename

    # 图片path和名称组成图片的保存路径
    file_path = path + imgName

    # 保存图片
    imgData.save(file_path)

    # url是图片的路径
    url = '/static/upload/img/' + imgName
    print(url)
    
    return 'ok'
